﻿using System;
using System.Collections.Generic;

using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace HDJ.Framework.Core
{
    public static class NetworkUtils
    {
        public static IPAddress[] GetLocalIP(AddressFamily addressFamily)
        {
            string hostName = Dns.GetHostName();//本机名   
            Debug.Log("hostName :" + hostName);

            IPAddress[] addressList = Dns.GetHostAddresses(hostName);//会返回所有地址，包括IPv4和IPv6 
            List<IPAddress> list = new List<IPAddress>();
            for (int i = 0; i < addressList.Length; i++)
            {
                IPAddress ip = addressList[i];
                if (ip.AddressFamily == addressFamily)
                {
                    list.Add(ip);
                }
            }
            return list.ToArray();
        }
    }
}
